/*    
    OpenMheg - A free MHEG-5 library
    Copyright (C) 2008 Dharmesh Malam

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Xml;
using Core.Model.Data.Generics;

namespace XMHEGDecoder.Builders
{
    public class ColourBuilder
    {

        public static GenericColour Build ( XmlElement node )
        {
            GenericColour colour = new GenericColour (Color.Transparent);

            XmlElement e;
            if ( ( e = node ["colour-index"] ) != null )
            {
                throw new Exception("No CLUT defined in 1.06");
                //colour = Lookup( DecodeUtils.ParseInt( e.InnerText ) );
            }
            else if ( ( e = node ["absolute-colour"] ) != null )
            {
                colour = DecodeUtils.LookupGenericColour(  e.InnerText  );
            }
            else if ( ( e = node ["new-absolute-colour"] ) != null )
            {
                if ( ( e = e ["indirect-reference"] ) != null )
                {
                    colour =  new GenericColour ( ObjectRefBuilder.Build( e ) );
                }
                else
                    colour = DecodeUtils.LookupGenericColour( node ["new-absolute-colour"] ["octetstring"].InnerText  );
            }
            else
                throw new Exception("Unknown Colour");

            return colour;
        }

        private static GenericColour Lookup ( int index )
        {
            throw new Exception( "oi" );
            //log.Warning("Colour Lookup tables not yet implemented");
            return new GenericColour (Color.FromArgb(112,Color.Gold));
            //return Color.FromArgb( 255, 0, 255 );
        }


    }
}
